<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ page import="dou.servletShopp.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'cart.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
	<%
		//从 session 当中，取出 cart 对象
	Cart cart = (Cart) session.getAttribute("cart");
		if (cart != null && cart.list().size() > 0) {
			List<CartItem> items = cart.list();
			for (int i = 0; i < items.size(); i++) {
				CartItem item = items.get(i);
	%>
	<tr>
		<td class="altbg2"><%=item.getP().getModel()%></td>
		<td class="altbg2"><%=item.getP().getPrice()%></td>
		<td class="altbg2"><%=item.getQty()%></td>
		<td class="altbg2"><input type="text" size="3" value="" id="num_<%=item.getP().getId()%>" /></td>
		<!-- 动态生成 id -->
		<td class="altbg2"><a href="javascript:;" onclick="location='modify.do?id=<%=item.getP().getId()%>&qty='+document.getElementById('num_<%=item.getP().getId()%>').value;">更改数量</a></td>
		<!-- 注意！location 中的地址不能用回车换行！ -->
		<td class="altbg2"><a href="delete.do?id=<%=item.getP().getId()%>">删除</a></td>
	</tr>
	<%
		}
	%>
	<tr>
		<td class="altbg1" colspan="6"><b>总价格：￥<%=cart.cost()%></b></td>
	</tr>
	<%
		} else {
	%>
	<tr>
		<td class="altbg2" colspan="6"><b>还没有选购商品</b></td>
	</tr>
	<%
		}
	%>
	<center>
		<input class="button" type="button" value="返回商品列表"
			name="settingsubmit" onclick="location = 'shopp/list.do';"> <input
			class="button" type="button" value="清空购物车" name="settingsubmit"
			onclick="location = 'shopp/clear.do';">
	</center>

</body>
</html>
